<?php
/**
 * 活动所关联项目的视频
 * @author Administrator
 *
 */
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use \DB;
class ActivityProjectVideo extends Model
{
	protected function getDateFormat()
	{
		return date(time());
	}
    //
	protected $table = 'activity_project_video';


    public function activity()
    {
        return $this->hasOne('App\Models\Activity', 'id', 'activity_id');
    }

    public function project()
    {
        return $this->hasOne('App\Models\Project', 'id', 'project_id');
    }

	/**
	 * 项目的视频数量
	 * @param unknown_type $project_id
	 */
	static function getVideoCountByPid($project_id){
		return self::where('project_id',$project_id)->count();
	}
	/**
	 * 获取视频的创客空间名字
	 * @param unknown_type $vid  路演视频id
	 */
	static function getMakerName($vid){
		$maker= DB::table('activity_project_video')
    	->leftJoin('maker_activity','activity_project_video.activity_id','=','maker_activity.activity_id')
    	->leftJoin('maker','maker_activity.maker_id','=','maker.id')
    	->select('maker.name as maker_name')
    	->where('activity_project_video.id','=',1)->first();
		  return $maker->maker_name;
	}
	/**
	 * 获取的视频评论
	 * @param unknown_type $vid
	 */
	static function getComments($vid){
		$comments=DB::table('activity_project_video')
		->leftJoin('activity_video_comment','activity_project_video.id','=','activity_video_comment.post_id')
		->leftJoin('user','user.uid','=','activity_video_comment.uid')
		->select('activity_project_video.image','user.realname','activity_video_comment.created_at','activity_video_comment.content')
		->where('activity_project_video.id','=',$vid)->get();
		return $comments;
	}
}
